home *** CD-ROM | disk | FTP | other *** search
- DOS-EDIT
-
- Charles Petzold
-
-
- DOS command-line editing facilities are primitive at best.
- Here's a memory-resident DOS-EDIT utility that saves you key
- strokes by providing full-screen editing.
-
- How many times have you reached for the CursorUp key to correct
- something you've mistyped at the DOS command level? I do it a
- lot. It's almost instinctive. The text is still there on the
- screen, so all you should have to do is move the cursor up, fix
- the text, and re-enter. But this natural keyboard maneuver
- doesn't work in DOS.
-
- I wrote DOS-EDIT to make it work. DOS-EDIT is a resident program
- that allows you to move to, edit, and re-execute DOS commands
- that are still on the screen, much as you can with the BASICA
- interpreter. And while of greatest use when you're on the DOS
- command level, DOS-EDIT will also work with such DOS programs as
- EDLIN or DEBUG, and with some other programs whose keyboard entry
- can be edited with the normal DOS editing keys (F1 to F5 and the
- cursor keys).
-
- If you don't know about the DOS editing keys, you should at least
- start by learning about them. Strangely enough, they got lost
- from PC-DOS 2.1 documentation when a separate User's Guide was
- split off from the main manual. (The User's Guide for PC-DOS 3.0
- and 3.1 does describe them, and they do work under Version 2.1.)
- The DOS editing keys themselves, however, can recall only the
- immediately previous command. DOS-EDIT is often easier to use
- than the DOS editing keys even for that, and it can also retrieve
- other commands still on the screen, as well.
-
- You can put DOS-EDIT.COM in your AUTOEXEC.BAT file so that it
- executes once and remains resident for the duration of your PC
- session. Because it intercepts resident programs, particularly
- those that can be executed more than once. If you use the DOS
- ASSIGN program, for example, you'll want to execute DOS-EDIT in
- your AUTOEXEC.BAT file before ASSIGN runs for the first time.
- The same holds true for SIDEKICK. In general, if DOS-EDIT does
- not seem to work at first, try placing it earlier in your
- AUTOEXEC.BAT and rebooting.
-
- DOS-EDIT ON YOUR MACHINE
-
- Once DOS-EDIT is loaded (normally through your AUTOEXEC.BAT
- file), you can best understand its operation by thinking of your
- keyboard input as being in one of two separate modes. The normal
- mode works just as you're accustomed, and you won't know DOS-EDIT
- is even resident. But when you press the Cursor up key, you
- enter the full-screen mode and DOS-EDIT kicks into action.
-
- While in full-screen mode, you can use the cursor keys to move
- the cursor to any part of the screen above the line from which
- you started. You are able to delete individual characters on the
- screen by pressing the Del key. The rest of the line to the
- right of the deleted character moves left. The Backspace key
- deletes the character to the left of the cursor and also moves
- the rest of the line left. The PgDn key deletes all characters
- from the cursor to the end of the line.
-
- You can also type in regular characters while in full-screen
- mode. The typed characters will either overtype existing test or
- be inserted into the line. The Ins key switches between these
- actions. The program starts with insert off.
-
- While in full-screen mode, the Home key moves the cursor horizon-
- tally to the original column position - the column the cursor was
- on when you entered full-screen mode - but keeps the cursor on
- the same line. The PgUp key moves the cursor horizontally to the
- first column position of the current line, all the way over to
- the left of the screen.
-
- You can exit from the full-screen mode and return to the line you
- started from in one of four different ways. First, if you move
- the cursor down to the original line, the cursor will instantly
- jump back to its original position and you'll be out of full-
- screen mode. Second, if you press Esc while in full-screen mode,
- you'll exit full screen mode with no changes made to your orig-
- inal line. Third, if you press End, DOS-EDIT will transfer all
- text from the cursor to the end of the line (except trailing
- blanks) to the original line and leave the cursor at the end of
- the original line. Fourth, pressing Enter does the same thing as
- End, except that it also enters the resulting command line.
-
- HOW DO I USE IT?
-
- The DOS-EDIT keystrokes may sound somewhat complex, but in actual
- use, you'll find them almost intuitive and simple to use. The
- Home key is the most important. Because Enter and End only move
- text that starts at the cursor position, you usually have to move
- the cursor to the beginning of the line, but not further left
- than the DOS prompt. Assuming you enter full-screen mode with
- the cursor just to the right of the DOS prompt, Home moves it
- back to that position.
-
- A few examples will clarify the keystrokes:
-
- 1. You entered a CD command but then realized you're on the
- wrong drive. To fix matters at this point, type in the correct
- drive, move the cursor up the CD line, and press Enter. (If the
- length of your prompt changes when you change drives, you must
- position the cursor under the C in CD before pressing Enter.)
-
- 2. You entered a long command but made a typing mistake. Move
- the cursor up to the line, correct the mistake (using the Del and
- Backspace keys and inserting characters as appropriate), press
- Home, and then Enter.
-
- 3. You just did a DIR listing and you want to run one of the
- listed programs. Move the cursor up the filename extension.
- Press PgDn to delete from the cursor to the end of the line. You
- can then enter any parameters, press PgUp to move the cursor to
- the left of the screen, and press Enter. Or, after deleting the
- filename extension, you can press PgUp to move the cursor to the
- beginning of the line, and End to transfer the line down to the
- command line without entering it. You may then enter the param-
- eters and press Enter.
-
- A PROGRAMMER'S PROBLEM
-
- I had originally wanted to make DOS-Edit work in exactly the same
- way as the BASICA interpreter. That is, I wanted it to accept
- the entire line wherever the cursor was positioned on the line.
- This didn't seem like a big deal, but programmers often find that
- a task that at first appears straightforward can develop an ugly
- little hitch on closer examination.
-
- The hitch in this case proved to be the DOS prompt. The DOS
- prompt is part of the line, but it is - inconveniently - a part
- of the line that DOS-EDIT must ignore.
-
- Why not just have DOS-EDIT ignore the first two characters on the
- line? No good. Most hard disk users I know use the PROMPT
- command with a $p$g argument to display the current subdirectory,
- so their prompts are longer than two characters. OK, then, why
- not just have DOS-EDIT ignore everything to the left of the first
- angle bracket character? That might be fine for your prompt, but
- mine doesn't even end with a right-angle bracket.
-
- The prompt problem was such a nuisance that I even went so far as
- to consider having DOS-EDIT look in the Environment area to get
- the actual prompt string so DOS-EDIT could know what it was and
- ignore it. But a resident program like DOS-EDIT gets only a
- static copy of the Environment when it's loaded. If you change
- the DOS prompt after DOS-EDIT is loaded, DOS-EDIT has no way of
- learning about the change.
-
- That is why DOS-EDIT only transfers text from the cursor position
- on, and why I provided the Home key to move the cursor back to
- the original starting column. When people ask of a program, "Why
- does it do it this way?" and "Wouldn't it make more sense to do
- it that way?" there are often good reasons. In the case of DOS-
- EDIT, the prompt made me do it.
-
- IT'S ALL IN THE INTERRUPTS
-
- For an assembly language program that needs to get a whole line
- of keyboard input, the DOS Interrupt 21h function call 0Ah (Buf-
- fered Keyboard Input) is often ideal. All the programmer has to
- do is set up an area in memory to receive the string of keyboard
- input, make the function call, and DOS does the rest. After the
- user presses Enter, DOS returns the final string back to the
- program.
-
- Moreover, if the string is returned intact to DOS the next time
- keyboard input is needed, DOS uses that string as a template and
- allows the user to recall and edit the string with the DOS func-
- tion keys. (Because function call 0Ah is susceptible to Ctrl-
- Break and skips to a new line when the Esc key is pressed, it is
- not often used in more complex programs like spreadsheets and
- word processors. These programs have their own logic to allow
- editing of command lines.)
-
- Function call 0Ah is the one that COMMAND.COM, DEBUG, and EDLIN
- all use for keyboard input. In one sense, all that DOS-EDIT has
- to do is add more functions to function call 0Ah to allow the
- user to move the cursor up to another part of the screen and
- retrieve previous commands or other text. But since the workings
- of this function call are deep in the guts of DOS, DOS-EDIT has
- to do the job in a roundabout manner.
-
- DOS-EDIT intercepts Interrupt 21h, but it only sets an internal
- flag if function call 0Ah is being requested. It then just lets
- the normal function call proceed. DOS-EDIT also intercepts
- Interrupt 16h, which is the BIOS service used for getting key-
- board input. When DOS is getting keyboard input for function
- call 0Ah, it ultimately must go to Interrupt 16h.
-
- DOS-EDIT monitors the Interrupt 16h calls for the Cursor up
- keystroke, which has no meaning to function call 0Ah. When DOS
- is currently performing a function call 0Ah and Interrupt 16h is
- ready to pass back a Cursor up keystroke, DOS-EDIT kicks into
- action and goes into full-screen mode.
-
- From that point on, DOS-EDIT is in control and handles all the
- cursor movement and editing of the display, using both Interrupt
- 16h and Interrupt 10h (the BIOS display interrupt). When you
- press Enter or End, DOS-EDIT reads the line from the screen and
- goes out of full-screen mode.
-
- At this point, DOS is still looking for keystrokes for its orig-
- inal function 0Ah call. DOS-EDIT supplies these keystrokes from
- the text it read off the screen. When this text is exhausted,
- DOS-EDIT relinquishes all control, and things return to normal
- again.
-
- You'll probably find that DOS-EDIT is habit-forming. It's one of
- those little utilities that after a little use almost seems like
- a proper part of DOS. But of course, that's the power of resi-
- dent programs: They let us change and customize DOS to make it
- more flexible and easier to use.
-